#pragma once

#include <vector>
#include "Enum.h"

class Item;
class Tool;
class MeleeWeapon;
class RangedWeapon;
class Npc;
class Obstacle;
class ItemContainer;
class Resource;
class Armor;
class Shield;

enum RandomItemType {
	RANDOM_ITEM_INGREDIENT = 0x0001,
	RANDOM_ITEM_MISC = 0x0002,
	RANDOM_ITEM_POTION = 0x0004,
	RANDOM_ITEM_TOOL = 0x0008,
	RANDOM_ITEM_MELEE_WEAPON = 0x0010,
	RANDOM_ITEM_FOOD = 0x0020,
	RANDOM_ITEM_SCROLL = 0x0040,
	RANDOM_ITEM_SHIELD = 0x0080,
	RANDOM_ITEM_ARMOR = 0x0100,
	RANDOM_ITEM_AMMO = 0x0200,
	RANDOM_ITEM_RANGED_WEAPON = 0x0040,
	RANDOM_ITEM_ALL = 0xFFFF
};

enum RandomObstacleType {
	RANDOM_OBS_ITEMCONTAINER = 0x0001,
	RANDOM_OBS_RESOURCE = 0x0002,
	RANDOM_OBS_TRAP = 0x0004,
	RANDOM_OBS_ALL = 0xFFFF
};

struct RandomObjectWeight {
	GenericType objectType;
	int type;
	int weight;
};

class RandomObjectGenerator {
protected:
	static int binarySearch(std::vector<RandomObjectWeight*> vec, int val);
	static int modifiedWeight(int dlevel, int ilevel, int commonality);
	static RandomObjectWeight* createRandomObjectWeight(GenericType objectType, int type, int weight);
public:
	static Item* getRandomItem(int dlevel, int type = RANDOM_ITEM_ALL);
	static Npc* getRandomNpc(int dlevel);
	static Obstacle* getRandomObstacle(int dlevel, int = RANDOM_OBS_ALL);
	static Item* createItem(GenericType objectType, int type, int dlevel);
	static Tool* createTool(ToolType type, int dlevel);
	static MeleeWeapon* createMeleeWeapon(MeleeWeaponType type, int dlevel);
	static RangedWeapon* createRangedWeapon(RangedWeaponType type, int dlevel);
	static Armor* createArmor(ArmorType type, int dlevel);
	static Shield* createShield(ShieldType type, int dlevel);
	static MaterialType getMaterialType(int dlevel, bool allowWood = true);
	static Obstacle* createObstacle(GenericType objectType, int type, int dlevel);
	static ItemContainer* createItemContainer(ItemContainerType type, int dlevel);
	static Resource* createResource(ResourceType);
};

